package com.onlinesys.action;

import java.util.List;

import com.onlinesys.beans.ProductRepository;
import com.onlinesys.service.ProductReprocessService;
import com.onlinesys.service.impl.ProductReprocessServiceImpl;
import com.onlinesys.utils.Page;
import com.opensymphony.xwork2.ActionSupport;

public class RepairlineInfoAction extends ActionSupport {
    private static final long serialVersionUID = 1L;

    private List<ProductRepository> pps = null;

    private int currentPage = 1;

    private int pageSize = 10;

    private String pageBar = null;

    private String drawingNum = null;

    private String search = null;
    
    private String vendor = null;
    
    private Double area;
    
    private String type = null;

    public String execute() throws Exception {
        ProductReprocessService pps = new ProductReprocessServiceImpl();
        ProductRepository pr = null;
        int totalCount = 0;
        String url = "repairlineInfo.action";
        StringBuilder searchStr = new StringBuilder();
        if (Boolean.valueOf(search)) {
            pr = new ProductRepository();
            searchStr.append("&search=true");
            if (drawingNum != null && !"".equals(drawingNum.trim())) {
                searchStr.append("&drawingNum=" + drawingNum);
                pr.setDrawingNum(drawingNum);
            }
            if (vendor != null && !"".equals(vendor.trim())) {
                searchStr.append("&vendor=" + vendor);
                pr.setVendor(vendor);
            }
            if (area != null) {
                searchStr.append("&area=" + area);
                pr.setArea(area);
            }
            
            this.pps = pps.searchProductReprocesses((currentPage - 1) * pageSize, pageSize, pr);
            totalCount = pps.searchProductReprocessTotalCount(pr);
        } else {
            this.pps = pps.getProductReprocesses((currentPage - 1) * pageSize, pageSize);
            totalCount = pps.getProductReprocessTotalCount();
        }
        pageBar = Page.PageBar(totalCount, pageSize, currentPage, url, searchStr.toString());

        return SUCCESS;
    }

    public String getDrawingNum() {
        return drawingNum;
    }

    public void setDrawingNum(String drawingNum) {
        this.drawingNum = drawingNum;
    }

    public List<ProductRepository> getPps() {
        return pps;
    }

    public void setPps(List<ProductRepository> pps) {
        this.pps = pps;
    }

    public String getPageBar() {
        return pageBar;
    }

    public void setPageBar(String pageBar) {
        this.pageBar = pageBar;
    }

    public int getCurrentPage() {
        return currentPage;
    }

    public void setCurrentPage(int currentPage) {
        this.currentPage = currentPage;
    }

    public int getPageSize() {
        return pageSize;
    }

    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
    }

    public String getSearch() {
        return search;
    }

    public void setSearch(String search) {
        this.search = search;
    }

    public String getVendor() {
        return vendor;
    }

    public void setVendor(String vendor) {
        this.vendor = vendor;
    }

    public Double getArea() {
        return area;
    }

    public void setArea(Double area) {
        this.area = area;
    }

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

}
